package com.henghe.frame.common.entity;

import com.henghe.frame.common.constants.CommonConstants;
import lombok.Data;

/**
 * Description:
 * Author: LiuWenQing
 * Datetime: 2023/3/15 16:33
 */
@Data
public class Result {

    private Integer code;
    private String msg;
    private Object data;

    public static Result ok() {
        Result r = new Result();
        r.setCode(CommonConstants.SUCCESS_CODE);
        r.setMsg("操作成功");
        return r;
    }

    public static Result error() {
        Result r = new Result();
        r.setCode(CommonConstants.FAIL_CODE);
        r.setMsg("操作失败");
        return r;
    }

    public static Result error(String msg) {
        Result r = new Result();
        r.setCode(CommonConstants.FAIL_CODE);
        r.setMsg(msg);
        return r;
    }

    public static Result authError(String msg){
        Result r = new Result();
        r.setCode(CommonConstants.AUTH_ERROR_CODE);
        r.setMsg(msg);
        return r;
    }

    public static Result fieldError(String msg){
        Result r = new Result();
        r.setCode(CommonConstants.FIELD_ERROR_CODE);
        r.setMsg(msg);
        return r;
    }

    public static Result ok(Object o) {
        Result r = new Result();
        r.setCode(CommonConstants.SUCCESS_CODE);
        r.setMsg("操作成功");
        r.setData(o);
        return r;
    }

    public static Result ok(String msg, Object o) {
        Result r = new Result();
        r.setCode(CommonConstants.SUCCESS_CODE);
        r.setMsg(msg);
        r.setData(o);
        return r;
    }
}
